Advertisement
Guest User

Untitled

a guest
May 19th, 2021
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1.  
  2.  
  3. on pro mini:
  4.  
  5. 0 rxd rxd
  6. 1 txd txd
  7.  
  8. 2 pd2
  9. 3 pd3
  10.  
  11.  
  12. 4 pd4
  13. 5 pd5
  14. 6 pd6
  15. 7 pd7
  16.  
  17. 8 pb0 Data 0
  18. 9 pb1 Data 1
  19. 10 pb2
  20.  
  21.  
  22. 11 pb4
  23. 12 pb3
  24. 13 pb5
  25.  
  26.  
  27. A0 pc0 LCD D0
  28. A1 pc1 LCD D1
  29. A2 pc2 LCD D2
  30. A3 pc3 LCD D3
  31.  
  32. A4 pc4 LCD RS
  33. A5 pc5 LCD /E
  34.  
  35.  
  36. A6 adc6
  37. A7 adc7
  38.  
  39. LCD R/W goes to ground
  40. LCD Vlcd goes to 0-5V contrast pot.
  41.  
  42.  
  43. position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  44. line 1 0 1 2 3 4 5 6 7 40 41 42 43 44 45 46 47
  45.  
  46.  
  47.  
  48. */
  49. #include <avr/io.h>
  50. #include "usart.h"
  51. #include <avr/interrupt.h>
  52. #include "lcd.h"
  53.  
  54. #define NOP() asm volatile ("nop"::)
  55. #define OUTPUT 1
  56. #define INPUT 0
  57.  
  58. #define SetBit(BIT, PORT) PORT |= (1<<BIT)
  59. #define ClearBit(BIT, PORT) PORT &= ~(1<<BIT)
  60. #define IsHigh(BIT, PORT) (PORT & (1<<BIT)) != 0
  61. #define IsLow(BIT, PORT) (PORT & (1<<BIT)) == 0
  62. #define InBoundsI(v, l, h) ((v) >= (h)) ? (0) : ((v) <= (l)) ? (0) : (1)
  63.  
  64.  
  65. #define waitswipe() while((PINB & 0x03) == 0x03)
  66.  
  67. unsigned long readCode(void);
  68.  
  69. int main( void ) {
  70.  
  71. unsigned int i;
  72. unsigned long capture;
  73. unsigned int facility;
  74. unsigned int serial;
  75.  
  76.  
  77. // set up directions
  78. DDRB = (INPUT << PB0 | INPUT << PB1 | INPUT << PB2 |INPUT << PB3 |INPUT << PB4 |INPUT << PB5 |INPUT << PB6 |INPUT << PB7);
  79. DDRD = (INPUT << PD0 | INPUT << PD1 | INPUT << PD2 |INPUT << PD3 |INPUT << PD4 |INPUT << PD5 |INPUT << PD6 |INPUT << PD7);
  80. DDRC = (OUTPUT << PC0 | OUTPUT << PC1 | OUTPUT << PC2 |OUTPUT << PC3 |OUTPUT << PC4 |OUTPUT << PC5 |INPUT << PD6 |INPUT << PD7);
  81.  
  82. PORTB = 0x0C;
  83. lcd_init();
  84.  
  85. lcd_goto(0);
  86. lcd_putstr("Ready");
  87.  
  88. for ( i = 0; i < 65534; i++) NOP(); // startup delay for screen
  89.  
  90. lcd_cls();
  91. lcd_putstr("Ready");
  92.  
  93. while(1) {
  94. waitswipe();
  95. capture = readCode();
  96.  
  97. facility = (capture >> 16) & 255;
  98. serial = capture & 0xFFFF;
  99.  
  100. lcd_goto(0);
  101. lcd_putstr("F:");
  102. print3(facility);
  103. lcd_goto(40);
  104. lcd_putstr("SN:");
  105. print5(serial);
  106.  
  107. }
  108.  
  109. }
  110.  
  111.  
  112. //------------------------| FUNCTIONS |------------------------
  113.  
  114.  
  115.  
  116. unsigned long readCode(void) {
  117.  
  118. unsigned long data;
  119. unsigned long timeout;
  120.  
  121. data = 0;
  122. while(1) {
  123.  
  124. for(timeout = 2000*8; ((timeout != 0) && (( PINB & 0x03) == 0x03)); timeout--);
  125.  
  126. if (timeout != 0) {
  127. if (PINB & 0x01) {
  128. data |= 0x01;
  129. }
  130. data <<= 1;
  131. while((PINB & 0x03) != 0x03);
  132. } else {
  133. return data >> 2 ;
  134. }
  135. }
  136. }
  137.  
  138.  
  139.  
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement